struct Fib {
    a: u32,
    b: u32,
    odd_sum: u32,
}

impl Fib {
    fn default() -> Self {
        Fib {
            a: 0,
            b: 1,
            odd_sum: 0,
        }
    }

    fn step(&mut self) {
        if self.b % 2 == 1 {
            self.odd_sum += self.b;
        }
        self.b += self.a;
        self.a = self.b - self.a;
    }
}

pub fn odd_fibnacci_sum(threshold: u32) -> u32 {
    let mut fib = Fib::default();
    while fib.b <= threshold {
        fib.step();
    }
    fib.odd_sum
}
